Passed
Pull Request — master (#101)
by Mathieu
01:28
created

User   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 73
dl 0
loc 84
c 0
b 0
f 0
rs 10

10 Functions

Rating   Name   Duplication   Size   Complexity  
A updatePassword 0 3 1
A getPassword 0 3 1
A getLastName 0 3 1
A getFirstName 0 3 1
A getFullName 0 3 1
A getId 0 3 1
A getEmail 0 3 1
A getApiToken 0 3 1
A getRole 0 3 1
A update 0 5 1
1
import {Entity, Column, PrimaryGeneratedColumn, Index} from 'typeorm';
2
3
export enum UserRole {
4
  COOPERATOR = 'cooperator',
5
  EMPLOYEE = 'employee',
6
  ACCOUNTANT = 'accountant'
7
}
8
9
@Entity()
10
export class User {
11
  @PrimaryGeneratedColumn('uuid')
12
  private id: string;
13
14
  @Column({type: 'varchar', nullable: false})
15
  private firstName: string;
16
17
  @Column({type: 'varchar', nullable: false})
18
  private lastName: string;
19
20
  @Column({type: 'varchar', unique: true, nullable: false})
21
  private email: string;
22
23
  @Index('api-token')
24
  @Column({type: 'varchar', nullable: true})
25
  private apiToken: string;
26
27
  @Column({type: 'varchar', nullable: false})
28
  private password: string;
29
30
  @Column('enum', {enum: UserRole, nullable: false})
31
  private role: UserRole;
32
33
  @Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'})
34
  private createdAt: Date;
35
36
  constructor(
37
    firstName: string,
38
    lastName: string,
39
    email: string,
40
    apiToken: string,
41
    password: string,
42
    role: UserRole
43
  ) {
44
    this.firstName = firstName;
45
    this.lastName = lastName;
46
    this.email = email;
47
    this.apiToken = apiToken;
48
    this.password = password;
49
    this.role = role;
50
  }
51
52
  public getId(): string {
53
    return this.id;
54
  }
55
56
  public getFirstName(): string {
57
    return this.firstName;
58
  }
59
60
  public getLastName(): string {
61
    return this.lastName;
62
  }
63
64
  public getEmail(): string {
65
    return this.email;
66
  }
67
68
  public getApiToken(): string {
69
    return this.apiToken;
70
  }
71
72
  public getPassword(): string {
73
    return this.password;
74
  }
75
76
  public getRole(): UserRole {
77
    return this.role;
78
  }
79
80
  public getFullName(): string {
81
    return `${this.firstName} ${this.lastName}`;
82
  }
83
84
  public update(firstName: string, lastName: string, email: string): void {
85
    this.firstName = firstName;
86
    this.lastName = lastName;
87
    this.email = email;
88
  }
89
90
  public updatePassword(password: string): void {
91
    this.password = password;
92
  }
93
}
94